package imp

import (
	"bgs/cache/redisImp"
	"bgs/conf"
	"bgs/db"
	"bgs/grpc/client"
	storeGrpc "bgs/grpc/gen/service/store"
	storeEndorseRequestGrpc "bgs/grpc/gen/service/store_endorse_request"
	storeFanGrpc "bgs/grpc/gen/service/store_fan"
	storeFollowGrpc "bgs/grpc/gen/service/store_follow"
	storeSpokesmanGrpc "bgs/grpc/gen/service/store_spokesman"
	activityService "bgs/service/activity"
	brandService "bgs/service/brand"
	productService "bgs/service/product"
	spokesmanService "bgs/service/spokesman"
	storeService "bgs/service/store"
	userService "bgs/service/user"
	"bgs/util"
	wxpMinaService "bgs/wxp/mina"
	"context"
	"go.uber.org/zap"
)

// StoreAPIService :grpc server proxy of store
type StoreAPIService struct {
	dao    *db.PgDao
	slog   *zap.SugaredLogger
	cacher *cache.Adapter
	storeGrpc.StoreOpServer
	storeEndorseRequestGrpc.StoreEndorseRequestOpServer
	storeFanGrpc.StoreFanOpServer
	storeFollowGrpc.StoreFollowOpServer
	storeSpokesmanGrpc.StoreSpokesmanOpServer
	activityService  *activityService.ActivityServiceImp
	brandService     *brandService.BrandServiceImp
	productService   *productService.ProductServiceImp
	spokesmanService *spokesmanService.SpokesmanServiceImp
	storeService     *storeService.StoreServiceImp
	userService      *userService.UserServiceImp
	wxpMinaService   *wxpMinaService.MinaServiceImp
}

// New initialization
func New(
	pgdao *db.PgDao,
	slog *zap.SugaredLogger,
	vars *conf.VarsSection,
	proxy *client.GrpcClientProxy,
	adp *cache.Adapter,
	activityService *activityService.ActivityServiceImp,
	brandService *brandService.BrandServiceImp,
	productService *productService.ProductServiceImp,
	spokesmanService *spokesmanService.SpokesmanServiceImp,
	storeService *storeService.StoreServiceImp,
	userService *userService.UserServiceImp,
	wxpMinaService *wxpMinaService.MinaServiceImp,
) *StoreAPIService {
	return &StoreAPIService{
		dao:              pgdao,
		slog:             slog.With("module", "StoreAPIService"),
		cacher:           adp,
		activityService:  activityService,
		brandService:     brandService,
		productService:   productService,
		spokesmanService: spokesmanService,
		storeService:     storeService,
		userService:      userService,
		wxpMinaService:   wxpMinaService,
	}
}

// NewContextLogger create a SugaredLogger with contextvalue
func (s *StoreAPIService) NewContextLogger(ctx context.Context) *zap.SugaredLogger {
	return util.NewContextLogger(ctx, s.slog)
}
